#ifndef CONTROLLER_H
#define CONTROLLER_H

#include <QKeyEvent>

#include "Cell.h"
#include "Object.h"
class Mob;
class Controller;

  // returns rrandom controller
Controller* randController();

#define AIENABLED  // enables AI in all controllers

  // parent class for all controllers
class Controller
{
    public:
        static const int BASEMOVEMENTCOST = 1;
        static const int SEARCHDEPTH = 20;

        Controller( Mob* mob_ = 0 )
            : mob(mob_), targetX(0), targetY(0)
        {}

          // decides what a mob should do
        virtual bool action( QKeyEvent* event = 0 ) = 0;

        Mob* getMob() const { return mob; }
        int getTargetX() const { return targetX; }
        int getTargetY() const { return targetY; }

        void setMob( Mob* i ) { mob = i; }
        void setTargetX( int i ) { targetX = i; }
        void setTargetY( int i ) { targetY = i; }

        void clearPath() { path.clear(); }
        Cell getPath();
        bool hasPath();
          // is used to indetify the controller for saving
        virtual char getType() const = 0;

        virtual ~Controller() {}
    protected:
          // is used to deermine if evasion is required and to try to evade from bullets
        bool evade();
          // findds path from [x1][y1] to [x2][y2]
        void findPath( int x1, int y1, int x2, int y2 );
    private:
          // pointer to controller's owner
        Mob* mob;
          // stores current path of mob
        std::list<Cell> path;
          // coordinates of mob's target;
        int targetX, targetY;
};


#endif // CONTROLLER_H
